package member.contoller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import member.domain.Member;
import member.service.MemberService;

/**
 * Servlet implementation class SearchMemberServlet
 */
public class SearchMemberServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	doPost(request, response);
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String id = null;
		String url = null;

		//1. 요청 파라미터 조회(검증)
		id = request.getParameter("id");
		
		//2. Business 처리 조회
		if(id!=""){
			MemberService service = MemberService.getInstance();
			Member mem = service.searchMemberById(id);

			request.setAttribute("member", mem);
			url = "/member/member_info.jsp";
			RequestDispatcher rdp = request.getRequestDispatcher(url);
			rdp.forward(request, response);
		}else{
			url = "/member/search_member.jsp";
			
			request.setAttribute("message", "아이디가 입력되지 않았습니다.");
			RequestDispatcher rdp = request.getRequestDispatcher(url);
			rdp.forward(request, response);
		}

	}

}
